package cn.hd01.repository;

import java.math.BigDecimal;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import cn.hd01.repository.entity.WithdrawBook;

@Repository
public interface WithdrawBookRepository extends JpaRepository<WithdrawBook, Integer> {

	Page<WithdrawBook> findAll(Specification<WithdrawBook> spec, Pageable pageable);
	
	Page<WithdrawBook> findByRefIdAndType(Integer refId, String type, Pageable pageable);
	
	@Query(value="select sum(withdrawRebate) from WithdrawBook where status = 0 and create_time >= ?1 and create_time <= ?2")
	BigDecimal findWithdrawRebate(String beginDate, String endDate);
	
	@Query(value="select sum(withdrawRebate) from WithdrawBook where status = 0")
	BigDecimal findWithdrawRebate();
	
	@Query(value="select sum(withdrawRebate) from WithdrawBook where status = 0 and create_time >= ?1")
	BigDecimal findWithdrawRebateByBegin(String beginDate);
	
	@Query(value="select sum(withdrawRebate) from WithdrawBook where status = 0 and create_time <= ?1")
	BigDecimal findWithdrawRebateByEnd(String beginDate);
}
